package cn.kailangtu.dataspot.security;

import android.os.Handler;
import android.os.Looper;

// 在主应用中启动 WatchDog
public class ANRWatchDog extends Thread {
    private static final int THRESHOLD_MS = 5000; // 5秒阈值
    private volatile long lastTick;

    public ANRWatchDog() {
        start();
    }

    @Override
    public void run() {
        while (!isInterrupted()) {
            lastTick = System.currentTimeMillis();
            // 主线程定期更新心跳
            new Handler(Looper.getMainLooper()).post(() -> lastTick = System.currentTimeMillis());
            try {
                sleep(THRESHOLD_MS);
            } catch (InterruptedException e) {
                break;
            }
            if (System.currentTimeMillis() - lastTick > THRESHOLD_MS) {
                // 触发 ANR 处理逻辑
                //notifyMonitorProcess();
            }
        }
    }
}
